1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| #include <cstdio> #include <functional> #include <algorithm> #include <cctype> #define LL long long const int maxn = 3005; const LL mo = 998244353; using namespace std; inline LL read(){ LL x = 0; char ch = getchar(); while (!isdigit(ch)) ch = getchar(); while (isdigit(ch)) x = x * 10 + (ch & 15), ch = getchar(); return x; } LL pow(LL x, LL t){ LL res = 1; x %= mo; while (t > 0){ if (t & 1) res = res * x % mo; x = x * x % mo; t >>= 1; } return res; } LL f[maxn][maxn][2], g[maxn][maxn][2]; LL fac[maxn], inv[maxn], a[maxn], b[maxn]; LL c[maxn][maxn]; LL C(int n, int m){ if (m == 0 || m == n) return 1; if (m > n) return 0; return c[n][m]; return 1ll * fac[n] * inv[m] % mo * inv[n - m] % mo; } int T, n, m, k; int main(){ scanf("%d", &T); int pre = 1; while (T--){ scanf("%d%d%d", &n, &m, &k); for (int i = 1; i <= n; i++) a[i] = read(); sort(a + 1, a + n + 1, greater<LL>()); for (int i = 1; i <= n; i++) b[i] = read(); sort(b + 1, b + n + 1, greater<LL>());
c[0][0] = 1; for (int i = pre; i <= 2 * n; i++) for (int j = 0; j <= i; j++) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mo; f[0][0][1] = 1; f[0][0][0] = 1; for (int i = 1; i <= n; i++){ f[i][0][1] = 1ll; for (int j = 1; j <= i; j++){ f[i][j][1] = (f[i - 1][j][1] + 1ll * a[i] * f[i - 1][j - 1][1] % mo) % mo; f[i][j][0] = 1ll * a[i] * f[i - 1][j - 1][1] % mo; g[i][j][1] = (g[i - 1][j][1] + 1ll * C(i - 1, j - 1) * b[i] % mo + g[i - 1][j - 1][1]) % mo; g[i][j][0] = (1ll * C(i - 1, j - 1) * b[i] % mo + g[i - 1][j - 1][1]) % mo; } } LL ans = 0; for (int x = 0; x < k - 1; x++) for (int j = 1; j <= n; j++) ans = (ans + 1ll * f[n][x][1] * g[j][k - x][0] % mo * C(n - j, m - k) % mo) % mo; for (int i = k - 1; i <= n; i++) for (int j = 1; j <= n; j++) ans = (ans + 1ll * f[i][k - 1][0] * b[j] % mo * C(n - i + n - j, m - k) % mo) % mo; printf("%lld\n", ans); pre = 2 * n; } return 0; }
|